package com.arges.web.dao;

import org.springframework.stereotype.Repository;

import com.arges.web.domain.pojo.Doc;

/**
 * 用户dao
 *
 * @author zxj
 */
@Repository
public class DocDao extends GenericDao<Doc, Long>
{

	public final static String TABLE_NAME = "DOCTOR";

	public Doc getByName(String name)
	{
		String hql = "from Doc d where d.name=?";
		return (Doc) getSession().createQuery(hql).setParameter(0, name).uniqueResult();
	}

	public void deleteDocByIds(Long[] deleteId)
	{
		StringBuffer hql = new StringBuffer();
		hql.append("delete from Doc where id in (");
		for (int i = 0; i < deleteId.length; i++)
		{
			hql.append(deleteId[i] + ",");
		}
		hql.deleteCharAt(hql.length() - 1).append(")");
		getSession().createQuery(hql.toString()).executeUpdate();
	}

	public void unFreeDoc(Long[] updateId)
	{
		StringBuffer hql = new StringBuffer();
		hql.append("Update Doc set status=0 where id in (");
		for (int i = 0; i < updateId.length; i++)
		{
			hql.append(updateId[i] + ",");
		}
		hql.deleteCharAt(hql.length() - 1).append(")");
		getSession().createQuery(hql.toString()).executeUpdate();
	}

	public void freeDoc(Long[] updateId)
	{
		StringBuffer hql = new StringBuffer();
		hql.append("Update Doc set status=1 where id in (");
		for (int i = 0; i < updateId.length; i++)
		{
			hql.append(updateId[i] + ",");
		}
		hql.deleteCharAt(hql.length() - 1).append(")");
		getSession().createQuery(hql.toString()).executeUpdate();
	}

}
